package com.egg.ylt;

import android.os.Build;
import android.os.StrictMode;
import android.util.DisplayMetrics;

import com.egg.ylt.Utils.Constants;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.yonyou.framework.library.BaseApplication;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;

/**
 * Created by sichaoqi on 2018/7/20.
 */

public class MyApplication extends BaseApplication {

    private AppSharedPreferences mSp;

    @Override
    public void onCreate() {
        super.onCreate();
        mSp = new AppSharedPreferences(getApplicationContext());
        //初始化公共参数
        Constants.TOKEN = mSp.getString(Constants.USER_TOKEN);
//        Constants.COMPANYID = mSp.getString(Constants.COMPANY_ID);
        Constants.SHOPID = mSp.getString(Constants.SHOP_ID);
        Constants.USERID = mSp.getString(Constants.USER_ID);
        Constants.BABYID = mSp.getString(Constants.BABY_ID);
        Constants.USERPHONE = mSp.getString(Constants.USER_PHONE);
        Constants.SWIMRINGCODE = mSp.getString(Constants.SWIM_RING_CODE);

        Constants.SCREEN_WIDTH = getResources().getDisplayMetrics().widthPixels;
        //初始化微信支付ID
        final IWXAPI api = WXAPIFactory.createWXAPI(getApplicationContext(), Constants.WX_APP_ID, true);
        api.registerApp(Constants.WX_APP_ID);


        //建议在application 的onCreate()的方法中调用
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
        /**
         *注意：如果您已经在AndroidManifest.xml中配置过appkey和channel值，可以调用此版本初始化函数。
         */
//        UMConfigure.init(mInstance, 0, "");

        //初始化扫描二维码
        ZXingLibrary.initDisplayOpinion(getApplicationContext());

        //友盟分享的初始化
        setUMShareInit();

        Fresco.initialize(this);

    }

    public void setUMShareInit() {

        /**
         * 设置组件化的Log开关
         * 参数: boolean 默认为false，如需查看LOG设置为true
         */
        UMConfigure.setLogEnabled(true);
        UMConfigure.init(this, "5b92379ff29d98287b0001f2", "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");

        PlatformConfig.setWeixin("wxb3b603b1b6dd65b4", "1bfb91325f2fe4e34c242472684f384a");
        //豆瓣RENREN平台目前只能在服务器端配置
//        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com");
        PlatformConfig.setQQZone("101529801", "f9cf674fdef3f216d3394bd9bd712ee0");
    }
}
